package com.aaa.system.Controller.Api;

import com.aaa.entity.User;
import com.aaa.system.aop.annotation.Log;
import com.aaa.system.service.UserService;
import com.aaa.system.vo.UserVo;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("system/api/user")
public class ApiUserController {

    @Autowired
    private UserService userService;

    @GetMapping("/info")
    public Result<User> getInfo(){
        return userService.getUserInfo();
    }

    //查询用户的信息、模糊查询、分页
    @PostMapping("/searchUser")
    public Result<IPage<User>> searchUser(@RequestBody UserVo userVo){
        return userService.findByCondition(userVo);
    }

    /**
     * 添加或者修改数据
     * @param user
     * @return
     */
    @PostMapping("/saveOrUpdate")
    @Log(title = "添加/修改用户",business_type = "2")
    public Result<Boolean> saveOrUpdate(@RequestBody User user){
        return userService.saveOrUpd(user);
    }
    /**
     * 删除用户信息
     */
    @DeleteMapping("delUser/{userId}")
    @Log(title = "删除用户",business_type = "3")
    public Result<Boolean> delUser(@PathVariable Long userId){
        return userService.delOneUser(userId);
    }

    /**
     * 批量修改
     * @param userIds
     * @return
     */
    @DeleteMapping("bachUser/{userIds}")
    @Log(title = "批量删除用户信息",business_type = "3")
    public Result<Boolean> bachUser(@PathVariable Long[] userIds){
        return userService.bachListUser(userIds);
    }
    /**
     * 退出登录  清除redis
     */
    @GetMapping("logout")
    public Result<Boolean> clearRedis(){
         return userService.clearRedis();
    }
    /**
     * 修改用户密码
     */
    @PostMapping("updUserPassword/{olePass}/{pass}")
    @Log(title = "修改用户密码",business_type = "3")
    public Result<Boolean> updUserPassword(@PathVariable String olePass,@PathVariable String pass){
        return userService.updUserPassword(olePass,pass);
    }
    /**
     * 上传头像
     */
    @PostMapping("uploadFile")
    public Result<String> uploadFile(HttpServletRequest request, MultipartFile file){
        return userService.uploadFile(request,file);
    }
}
